package com.vhall.component.entity.data.enums;

import lombok.Getter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

/**
 * SelectTimeIntervalOptionsEnum-
 *
 * @author xing.wang
 * @date 2023/11/20
 */
@Getter
public enum SelectTimeIntervalOptionsEnum {
    PAST_7_DAYS("最近7天",1,7),
    PAST_30_DAYS("最近30天",2,30),
    PAST_90_DAYS("最近90天",3,90),
    PAST_YEAR("最近一年",4,0),
    CURRENT_YEAR("本年度",5,0);

    private final String description;
    private final Integer index;
    private final Integer day;
    public String getStartTime(){
        LocalDate today = LocalDate.now();
        if (SelectTimeIntervalOptionsEnum.PAST_7_DAYS.equals(this)) {
            return today.plusDays(-7).format(DateTimeFormatter.ISO_LOCAL_DATE);
        }else if (SelectTimeIntervalOptionsEnum.PAST_30_DAYS.equals(this)) {
            return today.plusDays(-30).format(DateTimeFormatter.ISO_LOCAL_DATE);
        }else if (SelectTimeIntervalOptionsEnum.PAST_90_DAYS.equals(this)) {
            return today.plusDays(-90).format(DateTimeFormatter.ISO_LOCAL_DATE);
        }else if (SelectTimeIntervalOptionsEnum.PAST_YEAR.equals(this)) {
            return today.plusYears(-1).format(DateTimeFormatter.ISO_LOCAL_DATE);
        }else if (SelectTimeIntervalOptionsEnum.CURRENT_YEAR.equals(this)) {
            return today.with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ISO_LOCAL_DATE);
        }
        return null;
    }
    SelectTimeIntervalOptionsEnum(String description, Integer index,Integer day) {
        this.description = description;
        this.index = index;
        this.day = day;
    }
}
